<?php
namespace app\home\model;
use think\Db;
use think\Model;

class PatrolTaskM extends Model{
    protected $table = 'patrol_task'; // 设置当前模型对应的完整数据表名称
    protected $pk = 'PatrolTaskID';

    // 模型初始化
    protected static function init()
    {
        //TODO:初始化内容
    }
    public function listP(){
        $r=wmap(input(''));
        $total = PatrolTaskM::where($r[1])->count();
        $list = Db::view('patrol_task a', '*')
            ->view('sys_user u', 'UserName as UpdateName', 'a.Updater=u.UserId', 'left')
            ->where($r[1])
            ->page($r[0][0],$r[0][1])
            ->order('CreateTime desc')
            ->select();
//        lasd();die;
        return [
            'total'=>$total,
            'page'=>$r[0][0],
            'size'=>$r[0][1],
            'list'=>$list
        ];
    }
    public function saveMore($data){
        $m = new PatrolTaskM();
        $data['Creator'] = session('user.UserId');
        // saveAll方法新增数据默认会自动识别数据是需要新增还是更新操作，当数据中存在主键的时候会认为是更新操作
        return $m->allowField(true)->saveAll($data);
    }

    public function delOne(){
        return PatrolTaskM::destroy(input($this->pk));
    }


}